home *** CD-ROM | disk | FTP | other *** search
- #include <Folders.h>
- #include "defs.h"
-
- #include "Prefs.h"
-
- #define ALLOCATE_RESOURCE_DATA 1
- #include "embedded resources.h"
-
-
- /*
- This routine is called in two modes:
- * Usually, we just need to get the settings from the prefs file,
- and then close it.
- * If, however, we are going to be using the configuration dialog,
- we want to leave the file open.
- */
-
- void Get_prefs( file_disposition disp, Handle my_h )
- {
- long pref_dirID;
- short pref_vRefNum;
- short save_resfile;
- Boolean newfile = false;
- Boolean **config_h;
- Handle new_res_h;
- long total_size, contig_size;
- FInfo info;
- Str255 pref_name;
- short my_id;
- ResType my_type;
-
- save_resfile = CurResFile();
- pref_resfile = -1; // if this stays -1, it indicates failure
-
- // Contruct the prefs file name from the resource name
- GetResInfo( my_h, &my_id, &my_type, pref_name );
- BlockMove( " Settings", &pref_name[ pref_name[0] + 1 ], 9 );
- pref_name[0] += 9;
-
- FindFolder( kOnSystemDisk,'pref', kCreateFolder,
- &pref_vRefNum, &pref_dirID );
-
- /*
- At this point, unless something awful has happened, we have the
- dirID and vRefNum of the appropriate folder. Next we try to
- find the file by name.
- */
- pref_resfile = HOpenResFile( pref_vRefNum, pref_dirID,
- pref_name,
- (disp == p_read_only)? fsRdPerm : fsRdWrPerm );
-
- /*
- If we didn't find the file, we need to create it.
- */
- if (pref_resfile == -1)
- {
- HCreateResFile( pref_vRefNum, pref_dirID, pref_name );
- /*
- Since we look for the file by name, we lock the name.
- May as well set the type and creator here too.
- */
- (void) HGetFInfo( pref_vRefNum, pref_dirID, pref_name, &info );
- info.fdFlags |= 0x1000; /* nameLocked */
- info.fdType = 'pref';
- info.fdCreator = '????';
- (void) HSetFInfo( pref_vRefNum, pref_dirID, pref_name, &info );
- /*
- The file is ready, open it so we can add resources.
- */
- newfile = true;
- pref_resfile = HOpenResFile( pref_vRefNum, pref_dirID,
- pref_name, fsRdWrPerm );
- if (pref_resfile == -1)
- {
- SysBeep(1);
- return; /* give up */
- }
- }
-
- /*
- If we just created this file, we need to create a default
- configuration resource in it, otherwise we read the config.
- */
- if (newfile)
- {
- PurgeSpace( &total_size, &contig_size );
- if (total_size < 2000)
- {
- SysBeep(1);
- return;
- }
- config_h = (Boolean **) NewHandle( 3 );
- (*config_h)[0] = c_selected;
- (*config_h)[1] = false; // separate lines with hard returns
- (*config_h)[2] = false; // fake activate event
- AddResource( (Handle) config_h, CONFIG_TYPE, 128, "\p" );
-
- new_res_h = NewHandle( sizeof(DITL_data) );
- BlockMove( DITL_data, *new_res_h, sizeof(DITL_data) );
- AddResource( new_res_h, 'DITL', DITL_ID, "\p" );
-
- new_res_h = NewHandle( sizeof(DLOG_data) );
- BlockMove( DLOG_data, *new_res_h, sizeof(DLOG_data) );
- AddResource( new_res_h, 'DLOG', DLOG_ID, "\p" );
-
- new_res_h = NewHandle( sizeof(PICT_data) );
- BlockMove( &PICT_data, *new_res_h, sizeof(PICT_data) );
- AddResource( new_res_h, 'PICT', OUTLINE_PICT_ID, "\p" );
-
- new_res_h = NewHandle( sizeof(gray_PICT_data) );
- BlockMove( &gray_PICT_data, *new_res_h, sizeof(gray_PICT_data) );
- AddResource( new_res_h, 'PICT', GRAY_PICT_ID, "\p" );
-
- new_res_h = NewHandle( sizeof(text_PICT_data) );
- BlockMove( &text_PICT_data, *new_res_h, sizeof(text_PICT_data) );
- AddResource( new_res_h, 'PICT', TEXT_PICT_ID, "\p" );
-
- new_res_h = NewHandle( sizeof(copy_PICT_data) );
- BlockMove( ©_PICT_data, *new_res_h, sizeof(copy_PICT_data) );
- AddResource( new_res_h, 'PICT', COPY_PICT_ID, "\p" );
-
- UpdateResFile( pref_resfile );
- FlushVol( NIL, pref_vRefNum );
- }
- else
- {
- config_h = (Boolean **) Get1Resource( CONFIG_TYPE, 128 );
- }
- copy_mode = (*config_h)[0];
- spaces = (*config_h)[1];
- fake_activate = (*config_h)[2];
-
- UseResFile( save_resfile );
- if (disp == p_read_only)
- {
- CloseResFile( pref_resfile );
- }
- }
-
-
-
- void Set_prefs( void )
- {
- short save_resfile;
- Boolean **config_h;
-
- save_resfile = CurResFile();
- UseResFile( pref_resfile );
- config_h = (Boolean **) Get1Resource( CONFIG_TYPE, 128 );
- (*config_h)[0] = copy_mode;
- (*config_h)[1] = spaces;
- (*config_h)[2] = fake_activate;
- ChangedResource( (Handle) config_h );
- UpdateResFile( pref_resfile );
- UseResFile( save_resfile );
- }